package com.campus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus.common.ActivityStatusConstant;
import com.campus.common.core.Pager;
import com.campus.common.core.Result;
import com.campus.common.core.TableData;
import com.campus.model.TManagerActivity;
import com.campus.model.TManagerTeacher;
import com.campus.model.dto.*;
import com.campus.service.IManagerActivityService;
import com.campus.service.IManagerTeacherService;
import com.campus.service.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
@Api(tags = "教师管理")
public class ManagerTeacherController {

    @Autowired
    private IManagerTeacherService managerTeacherService;

    @Autowired
    private IUserRoleService userRoleService;

    @PostMapping("/add")
    @ApiOperation("新增教师")
    public Result<Integer> createManagerTeacher(@RequestBody @Validated TManagerTeacherCreateDto managerTeacherCreateDto){
        if (userRoleService.isExist(managerTeacherCreateDto.getLoginId())){
            return Result.error("该账号已绑定学生或教师");
        }
        return Result.success(managerTeacherService.createTeacher(managerTeacherCreateDto));
    }

    @PostMapping("/addTeacherUser")
    @ApiOperation("新增教师并直接添加为用户")
    public Result<Integer> createManagerTeacher(@RequestBody @Validated TManagerTeacherUserCreateDto createDto){

        return Result.success(managerTeacherService.createManagerTeacher(createDto));
    }

    @PutMapping("/update")
    @ApiOperation("修改教师")
    public Result<Integer> updateManagerTeacher(@RequestBody @Validated TManagerTeacherUpdateDto managerTeacherUpdateDto){
        return Result.success(managerTeacherService.updateTeacher(managerTeacherUpdateDto));
    }

    @GetMapping("/selectById/{id}")
    @ApiOperation("通过id查询教师")
    public Result<TManagerTeacher> selectManagerTeacher(@PathVariable Long id){
        return Result.success(managerTeacherService.selectById(id));
    }
 @GetMapping("/selectByTeacherName/")
    @ApiOperation("通过教师姓名查询教师")
    public Result<TManagerTeacher> selectManagerTeacher(@RequestParam String teacherName){
        return Result.success(managerTeacherService.selectByTeacherName(teacherName));
 }

}
